
var pay = {
    data() {
        return {
            payConfig: {
                show: false,
                mode: '1',
                priceType: 6, // 1 月卡 2 季卡
                type: 'alipay', // 1 支付宝 2微信
                data: {},
                money: '4.99',
                protocol: true
            },
        }
    },
    mounted() {
    },
    methods: {
        goPay() {

            this.$vux.loading.show();
            this.$http.post(`pay/order`, {
                //   mode:this.pay.mode,
                ...this.$route.query,
                base_front:1,
                base_access_token:this.userConfig.access_token,
                base_session_id:this.userConfig.session_id,
                base_udid:this.userConfig.base_udid,
                base_app_id:this.userConfig.base_app_id,
                base_project_id:this.userConfig.base_project_id,
                base_version:this.userConfig.base_version,

                return_url: `${location.origin}/communities/payReturn`,
                vip_level: this.payConfig.priceType,
                pay_method: this.payConfig.type
            }).then(({ data }) => {
                this.$vux.loading.hide();
                if (data.status === 1) {
                    sessionStorage.setItem('return_url',`${location.href}`)
                    /* if(this.payReturn != undefined && this.payReturn == false){
                        this.payReturn = true
                        this.userstate = false
                    }
                    if (this.$parent.$parent.payReturn != undefined && this.$parent.$parent.payReturn == false) {
                        this.$parent.$parent.payReturn = true
                        this.$parent.$parent.paystate = false
                    } */
                    if (data.data.pay_method === 'alipay') {
                        let div = document.createElement('div');
                        let ali = document.getElementById('alipay');
                        ali.innerHTML = '';
                        div.innerHTML = data.data.form;
                        // alert(data.data.form);
                        ali.appendChild(div);
                        document.forms['alipay_submit'].submit();
                    } else if (data.data.pay_method === 'wechat') {
                        location.href = data.data.url;
                    } else if (data.data.pay_method === 'hupijiao') {
                        location.href = data.data.url;
                    }
                } else {
                    this.$vux.toast.text(data.info, 'middle');
                }
            }).catch(error => {
                console.log(error)
                this.$vux.loading.hide();
                this.$vux.toast.text('服务器繁忙！', 'middle');
            });
        },
    },
    beforeDestroy() {

    },
}
export default pay